package com.gao.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;
@Controller
public class LoginController {
    //登录功能实现
//    @RequestMapping(value = "/user/login",method = RequestMethod.POST)
    @PostMapping("/user/login")
    public String loginIn(@RequestParam("username") String username, @RequestParam("password") String password,
                          Model model, HttpSession session){
        //&&"123456".equals(password)
        if(!StringUtils.isEmpty(username)){
            session.setAttribute("loginUser",username);
            return "redirect:/main.html";
        }else {
            model.addAttribute("msg","用户名密码错误");
            return "index";
        }

    }
}
